<?php


class Spy {
	
	private $logfile;
	private $path;
	private $debug;
	
	public function __construct($file = 'log', $deb = true, $path = false) {
		if (!$path) {
			$path = APP_PATH.'logs/';
		}
		
		$this->logfile = $file;
		$this->debug = $deb;
		$this->path = $path;
	}
	
	public function report() {
		
		$args = func_get_args();
		$fname = $this->path.date("d-m-Y").'_'.$this->logfile.'.log';
		
		foreach ($args as $arg) {
			if (is_array($arg)) {
				$msg = print_r($arg, true);
			} else {
				$msg = $arg;
			}
			
			error_log(date("[H:i:s] ").$msg."\n", 3, $fname);
		}
		
	}
	
	public function debug() {
		if (!$this->debug) return;
		$args = func_get_args();
		$reflectionMethod = new ReflectionMethod('Spy', 'report');
		$reflectionMethod->invokeArgs($this, $args);	
	}
	
	
}